/*
 * Filename:    WarnDownFileController.java
 * Copyright:   2014 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2014年12月6日
 */
package com.paic.mhis.hcpms.warning.web.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.paic.mhis.core.auth.biz.service.UserDetails;
import com.paic.mhis.hcpms.itextpdf.web.contoller.HcpmsOperateFile;
import com.paic.mhis.hcpms.warning.biz.service.HcpmsWarnService;
import com.paic.mhis.hcpms.warning.util.WarnConstants;
import com.paic.mhis.hcpms.warning.web.util.NoticeDocument;
import com.paic.mhis.hcpms.warning.web.util.ResultToldDocument;
import com.paic.pafa.appclient.annotation.BizServicesProxy;

@Controller
@RequestMapping("/HcpmsWarnDownFile/")
public class WarnDownFileController {
	@BizServicesProxy
	private HcpmsWarnService hcpmsWarnService;
	@Value("${fileDownloadPath}")
	private String filePath;

	/**
	 * 新增预警事件查询医护人员
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("downPdfFile.do")
	@ResponseBody
	public void downWarnPdfFile(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String warnNo = request.getParameter("warnNo");
		String docType = request.getParameter("docType");
		String warnNoBiz = request.getParameter("warnNoBiz");
		UserDetails user = (UserDetails) request.getSession().getAttribute("user");
		Map<String, Object> map = hcpmsWarnService.getWarnNotice(warnNo, WarnConstants.TASK_TYPE_WARNING, docType,
				user.getUsername());
		if ("".equals(filePath) || filePath == null) {

		} else if (WarnConstants.DOC_TYPE_NOTICE.equals(docType)) {
			// if ("".equals(map.get("warnNo")) || map.get("warnNo") == null) {
			// map.put("warnNo", warnNoBiz);
			// }
			HcpmsOperateFile notice = new HcpmsOperateFile(filePath, warnNo + "自查通知书.pdf");
			notice.careatePdfFile(new NoticeDocument(), map);
			notice.openPdfFile(response);
		} else if (WarnConstants.DOC_TYPE_TOLD.equals(docType)) {
			map.put("warnNo", warnNoBiz);
			HcpmsOperateFile notice = new HcpmsOperateFile(filePath, warnNo + "结果告知书.pdf");
			notice.careatePdfFile(new ResultToldDocument(), map);
			notice.openPdfFile(response);

		}
	}
}
